package com.margo.project.lru;

import java.util.LinkedHashMap;
import java.util.Map;

public class MargoLinkedHashMapLru {
	public static void main(String[] args) {
		int cacheSize = 3;
		LinkedHashMap<String, String> cache = new LinkedHashMap<String, String>((int) (cacheSize / 0.75f) + 1, 0.75f,
				true) {
			private static final long serialVersionUID = 1L;

			protected boolean removeEldestEntry(Map.Entry<String, String> eldest) {
				return size() > cacheSize;
			}
		};
		cache.put("1", "a");
		cache.put("2", "b");
		cache.put("3", "c");
		// 1 2 3 null

		// 3 1 4 null
		cache.put("4", "d");
		for (String key : cache.keySet()) {
			System.out.println(key);
		}
	}
}
